<template>
  <div>
    <!-- <img src="../assets/img/gg.jpg" alt="" width="100%" height="100%" v-if="!tuiJia"> -->
    <van-loading size="24px" vertical v-if="!tuiJia">加载中...</van-loading>
    <div class="home" v-if="tuiJia">
      <heads />
      <div class="lbt">
        <van-swipe class="my-swipe" :autoplay="3000" indicator-color="white">
          <van-swipe-item v-for="(item, index) in banners" :key="index">
            <img :src="item.cover" alt="" />
          </van-swipe-item>
        </van-swipe>
      </div>
      <div class="btn">
        <router-link class="mfBtn" tag="div" to="/freeBooks"
          >免费专区</router-link
        >
        <router-link class="nv" tag="div" to="/girlBooks">女频精选</router-link>
      </div>
      <div class="box">
        <div class="title">编辑力荐</div>
        <div
          class="item"
          v-for="(item, index) in tuiJia"
          :key="index + 'tj'"
          @click="goBook(item.id, item.title)"
        >
          <div class="img">
            <img :src="item.cover" alt="" width="100%" />
          </div>
          <div class="data">
            <div class="name">{{ item.title }}</div>
            <div class="p">
              {{ item.content }}
            </div>
            <div class="at-icon">
              <div class="at">{{ item.author }}</div>
              <div class="icon">
                <span class="icon1" v-if="item.category">{{ item.category }}</span>
                <span class="icon2">连载</span>
              </div>
            </div>
          </div>
        </div>
      </div>

      <div class="box box2">
        <div class="title">男生必读</div>
        <div class="item-box">
          <div
            class="item"
            v-for="item in boy[0]"
            :key="item.title"
            @click="goBook(item.id, item.title)"
          >
            <div class="img">
              <img :src="item.cover" alt="" width="100%" height="100%" />
            </div>
            <div class="name">{{ item.title }}</div>
          </div>
          <div
            class="item"
            v-for="item in boy[1]"
            :key="item.title"
            @click="goBook(item.id, item.title)"
          >
            <div class="img">
              <img :src="item.cover" alt="" width="100%" height="100%" />
            </div>
            <div class="name">{{ item.title }}</div>
          </div>
        </div>
      </div>
      <div class="box box2">
        <div class="title">女生必读</div>
        <div class="item-box">
          <div
            class="item"
            v-for="item in ges[0]"
            :key="item.title"
            @click="goBook(item.id, item.title)"
          >
            <div class="img">
              <img :src="item.cover" alt="" width="100%" height="100%" />
            </div>
            <div class="name">{{ item.title }}</div>
          </div>
          <div
            class="item"
            v-for="item in ges[1]"
            :key="item.title"
            @click="goBook(item.id, item.title)"
          >
            <div class="img">
              <img :src="item.cover" alt="" width="100%" height="100%" />
            </div>
            <div class="name">{{ item.title }}</div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import Heads from "../components/heads.vue";
import { getHomeData } from "../api/Home";
export default {
  name: "Home",
  components: { Heads },
  data() {
    return {
      tuiJia: null,
      banners: null,
      boy: [],
      ges: [],
      showPopover: false,
    };
  },
  methods: {
    goDetails() {
      this.$router.push({ path: "/bookDetails" });
    },
    goChapter() {
      this.$router.push({ path: "/chapter" });
    },
    goBook(id, name) {
      console.log(id, name);
      this.$router.push({
        path: "/bookDetails",
        query: { id: id, name: name },
      });
    },
  },
  created() {
    getHomeData().then((data) => {
      console.log(data);
      this.banners = data.data.list[0].banners;
      this.tuiJia = data.data.list[2].list;
      this.boy.push(data.data.list[3].list);
      this.boy.push(data.data.list[4].list);
      this.ges.push(data.data.list[5].list);
      this.ges.push(data.data.list[6].list);
    });
  },
  mounted() {},
};
</script>
<style lang="less">
.home {
  .head {
    display: flex;
    margin: 8px 10px;
    justify-content: space-between;
    align-items: center;
    .head_logo {
      background-size: 150px;
      height: 28px;
      width: 150px;

      background-image: url(https://static.zongheng.com/h5/v2016/images/pics.png);
      background-repeat: no-repeat;
    }
    .head_ulnk {
      span {
        color: rgb(153, 151, 151);
        font-size: 20px;
      }
      .icon-search {
        padding-right: 10px;
      }
      .but_client {
        padding-left: 10px;
        margin-left: 5px;
        border-left: 1px solid #d3d3d3;
      }
    }
  }
  .nav {
    height: 40px;
    line-height: 40px;
    display: flex;
    text-align: center;
    div {
      width: 25%;
      font-size: 16px;
      color: #a1a1a1;
      background-color: #333333;
      &.com {
        color: #f2f2f2;
        background-color: #454545;
      }
    }
  }
  .lbt {
    .my-swipe .van-swipe-item {
      color: #fff;
      height: 146px;
      img {
        width: 100%;
      }
    }
  }
  .btn {
    display: flex;
    padding: 11px 10px;
    justify-content: space-between;
    align-items: center;
    background-color: #fff;
    text-align: center;
    margin-bottom: 1px;
    div {
      width: 172px;
      height: 41px;
      border-radius: 5px;
      line-height: 41px;
      font-size: 12px;
      color: #fff;
      &.mfBtn {
        background-color: #7da3d7;
      }
      &.nv {
        background-color: #d0b2d3;
      }
    }
  }
  .box {
    padding: 21px 19px;
    background-color: #fff;
    .title {
      font-size: 18px;
      font-weight: 500;
      color: #333333;
      // margin-top: 21px;
      padding-left: 10px;
      border-left: 5px solid #e95e56;
      border-top-left-radius: 1px;
    }
    .item {
      display: flex;
      padding: 21px 0;
      border-bottom: 1px solid #f5f5f5;
      &:last-of-type {
        border: none;
        padding-bottom: 0px;
      }
      .img {
        width: 63px;
        height: 85px;
        padding: 1px;
        border: 1px solid #e3e2e1;
        background-color: pink;
        flex-shrink: 0;
        margin-right: 18px;
      }
      .data {
        .name {
          font-size: 16px;
          color: #333333;
          margin-bottom: 12px;
        }
        .p {
          font-size: 12px;
          color: #888888;
          overflow: hidden;
          text-overflow: ellipsis;
          display: -webkit-box;
          -webkit-line-clamp: 2; //多行在这里修改数字即可
          overflow: hidden;
          -webkit-box-orient: vertical;
        }
        .at-icon {
          font-size: 12px;
          color: #888888;
          display: flex;
          justify-content: space-between;
          margin-top: 10px;
          .icon {
            span {
              width: 53px;
              height: 15px;
              border-radius: 1px;
              color: #fff;
              margin-left: 10px;
              padding: 3px;
            }
            .icon1 {
              background-color: #d1acd8;
            }
            .icon2 {
              background-color: #a1d0d2;
            }
          }
        }
      }
    }
  }
  .box2 {
    margin-top: 10px;
    .item-box {
      display: flex;
      flex-wrap: wrap;

      .item {
        width: 33.3%;
        flex-direction: column;
        display: flex;
        border: none;
        &:last-of-type {
          padding-bottom: 21px;
        }
        .img {
          width: 90px;
          height: 110px;
          margin: auto;
        }
        .name {
          width: 90px;
          margin: auto;
          overflow: hidden;
          text-overflow: ellipsis;
          display: -webkit-box;
          -webkit-line-clamp: 2; //多行在这里修改数字即可
          overflow: hidden;
          -webkit-box-orient: vertical;
          height: 35px;
          font-size: 14px;
        }
      }
    }
  }
}
</style>
